var regWord = /^([\w\/.?&=]+)$/;
var regChar = /^([a-zA-Z\d]+)$/;

/**
 * 产品类型名输入框获取焦点，设置输入框校验显示信息列的样式
 * 
 * @param td_id_Col 菜单显示名校验显示列
 * @param s_id_Desc 提示信息显示Span ID
 */
function typeNameFocus(td_id_Col, s_id_Desc) {
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    var infoMsg = "产品类型名，必填，最长16个字符";
    displayInfoStyle(td_id_ColObj, s_id_DescObj, infoMsg);
}

/**
 * 产品类型名输入框失去焦点时的校验
 * 
 * @param i_obj
 * @param td_id_Col
 * @param s_id_Desc
 */
function typeNameBlur(i_obj, td_id_Col, s_id_Desc) {
	var chkResult = true;
	
    var objValue = i_obj.value;
    if(objValue) {
    	objValue = objValue.trim();
    	i_obj.value = objValue;
    }
    
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    
    var errMsg = "";
    if(objValue == "") {
        errMsg = "产品类型名不能为空";
    } else if(objValue.length > 16 ) {
        errMsg = "产品类型名最大长度为16个字符";
    }
    
    if(errMsg != "") {
        displayErrorStyle(td_id_ColObj, s_id_DescObj, errMsg);
        chkResult = false;
        return chkResult;
    }
    
    // 校验通过
    displayOkStyle(td_id_ColObj, s_id_DescObj);
    
    return chkResult;
}

/**
 * 产品类型名菜单URL输入框获取焦点，设置输入框校验显示信息列的样式
 * 
 * @param td_id_Col 产品类型名菜单URL校验显示列
 * @param s_id_Desc 提示信息显示Span ID
 */
function urlFocus(td_id_Col, s_id_Desc) {
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    var infoMsg = "产品类型名菜单URL，必填，最长128个字符";
    displayInfoStyle(td_id_ColObj, s_id_DescObj, infoMsg);
}

/**
 * 产品类型名菜单URL输入框失去焦点时的校验
 * 
 * @param i_obj
 * @param td_id_Col
 * @param s_id_Desc
 */
function urlBlur(i_obj, td_id_Col, s_id_Desc) {
	var chkResult = true;
	
    var urlV = i_obj.value;
    if(urlV) {
    	urlV = urlV.trim();
    	i_obj.value = urlV;
    }
    
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    
    var errMsg = "";
    if(urlV == "") {
        errMsg = "产品类型名菜单URL不能为空";
    } else if(!regWord.test(urlV)) {
        errMsg = "产品类型名菜单URL只能为字符";
    } else if(urlV.length > 128) {
    	errMsg = "产品类型名菜单URL最大长度为128个字符";
    }
    
    if(errMsg != "") {
        displayErrorStyle(td_id_ColObj, s_id_DescObj, errMsg);
        chkResult = false;
        return chkResult;
    }
    
    // 校验通过
    displayOkStyle(td_id_ColObj, s_id_DescObj);
    
    return chkResult;
}

/**
 * 产品类型标识输入框获取焦点，设置输入框校验显示信息列的样式
 * 
 * @param td_id_Col 产品类型标识校验显示列
 * @param s_id_Desc 提示信息显示Span ID
 */
function typeFlagFocus(td_id_Col, s_id_Desc) {
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    var infoMsg = "必填，最长32个字符，只能为字母数字";
    displayInfoStyle(td_id_ColObj, s_id_DescObj, infoMsg);
}

/**
 * 产品类型标识输入框失去焦点时的校验
 * 
 * @param i_obj
 * @param td_id_Col
 * @param s_id_Desc
 */
function typeFlagBlur(i_obj, td_id_Col, s_id_Desc) {
	var chkResult = true;
	
    var flagV = i_obj.value;
    if(flagV) {
    	flagV = flagV.trim();
    	i_obj.value = flagV;
    }
    
    var td_id_ColObj = document.getElementById(td_id_Col);
    var s_id_DescObj = document.getElementById(s_id_Desc);
    
    var errMsg = "";
    if(flagV == "") {
        errMsg = "产品类型标识不能为空";
    } else if(!regChar.test(flagV)) {
        errMsg = "产品类型标识只能为字符或数字";
    } else if(flagV.length > 32) {
    	errMsg = "产品类型标识最大长度为32个字符";
    }
    
    if(errMsg != "") {
        displayErrorStyle(td_id_ColObj, s_id_DescObj, errMsg);
        chkResult = false;
        return chkResult;
    }
    
    // 校验通过
    displayOkStyle(td_id_ColObj, s_id_DescObj);
    
    return chkResult;
}


/**
 * 添加新功能菜单表单提交
 */
function addProductTypeFun() {
	// 校验菜单显示名
	var typeNameObj = document.getElementById("typeName");
	if(!typeNameBlur(typeNameObj, 'typeNameCol', 'typeNameDesc')) {
		return false;
	}
	
	// 校验菜单URL
	var urlObj = document.getElementById("url");
	if(!urlBlur(urlObj, 'urlCol', 'urlDesc')) {
		return false;
	}
	
	// 校验产品类型标识
	var flagObj = document.getElementById("typeFlag");
	if(!typeFlagBlur(flagObj, 'typeFlagCol', 'typeFlagDesc')) {
		return false;
	}
	
	document.getElementById("producttypeCfgForm").submit();
    return true;
}

